function ajax({ type = "get", url, params = {} }) {
    return new Promise((resolve, reject) => {
        let xml = new XMLHttpRequest();
        let urlConcat = "";
        Object.keys(params).forEach((item, index) => {
            urlConcat += item + "=" + params[item] + "&"
        })
        urlConcat = urlConcat.substring(0, urlConcat.length - 1);
        if (type == "get") {
            xml.open(type, url + "?" + urlConcat);
            xml.send(null);
        } else {

            xml.open(type, url);
            xml.setRequestHeader("Content-type", "application/x-www-form-urlencoded; charset=utf-8");
            xml.send(urlConcat || null);
        }

        xml.onreadystatechange = function() {
            if (xml.readyState == 4) {
                if (xml.status == 200) {
                    resolve(JSON.parse(xml.responseText))
                } else {
                    reject(JSON.parse(xml.responseText))
                }
            }
        }
    })
}